﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Data.GameData;
using Data.GameData.Utils;

namespace GameFramework.Orders
{
    public class PlacePopulationOrder : Order
    {
        private SystemBody location = null;
        private Population startPopulation = null;

        public PlacePopulationOrder()
        {
            Type = OrderType.BUILD;
        }

        public SystemBody Location
        {
            get { return location; }
            set { location = value; }
        }

        public Population StartPopulation
        {
            get { return startPopulation; }
            set { startPopulation = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Fulfill()
        {
            if (Game.ActiveGame.TurnNumber < TurnComplete)
            {
                Status = OrderStatusType.IN_PROGRESS;
                return;
            }

            Race race = Race.Races.First(r => r.Id == startPopulation.OwnerId);

            if (location.Population == null)
            {
                Population pop = new Population(location, race.Id, Quantity);
                location.Population = pop;
                race.AddPopulation(pop);
            }
            else
            {
                location.Population.Size += Quantity;
            }

            Status = OrderStatusType.COMPLETE;
        }
    }
}
